<?php

/*
 * File: Amend POS
 * Description: To enable to editing of the current pos on the system, as well as add other pos if necessary
 * Author: Andrew Lowther
 * Version 1.0
 * Copyright: Carmba Marketing
 * Showing off: I typed this whole thing without even looking at my screen, looking around the office even as I type here.
 */
 
/*
 * The story of amending POS
 * One day there was a very uncomplete function.
 * It was the amend POS function, it didn't even have a page of its own.
 * So it sat in the chaos of nothingness, which is what things that don't exist do.
 * As other functions were created amend POS got more and more lonely :(
 * "Why have I not been created? I am a core function after all" it kept asking itself.
 * And then, one day, long after amend POS thought it had been forgotten, someone took up the mantle of creation.
 * It felt the code stir in its bowels and said "Oh, is this what coding feels like?".
 * In no time it was a fully functioning function, with all sorts of things in it, and even a page of its own.
 * amend POS then got to know its new friends, add POS and delete POS, and they all lived happily ever after.
 * ~FIN~
 */
 
// This is very useful, we're setting up some paths so that we don't have to type them everytime we include a file
$paths = array("core/", "display/", "db/", "config/", "users/", getcwd());
set_include_path(implode($paths, PATH_SEPARATOR));

// Should be all we need here
require_once 'config.php';
require_once 'main.class.php';
require_once 'genericdisplay.class.php';
require_once 'admindisplay.class.php';
require_once 'adminposdisplay.class.php';
require_once 'dbconnect.class.php'; 
require_once 'sessions.class.php';  
require_once 'userController.class.php';

// Instantiate our classes
$main = new main();
$sess= new Session();
$userController = new UserController(); 
$gendisplay = new Genericdisplay();
$admindisplay = new Admindisplay();
$promo = new Adminposdisplay();

// Start rendering our page
$gendisplay->body_open();
echo $gendisplay->html_header('admin_style.css');

if (!$_SESSION['lob']) {
	echo "There is no session line of business!";
}
	
?>

<div id="maincontainer">
	
	<?php echo $admindisplay->display_header(); ?>
	
	<div id="contentwrapper">
		<div id="contentcolumn">
			<div class="innertube">
			
				<?php
				
					// First of all check if we need to delete the POS
					if ($_GET['act']) {
					
						if ($_GET['act'] == "del") {
						
							$promo->deletePosItem($_GET['id']);
						
						}
						
						echo "POS Deleted successfully<br />\n";
						echo "<a href=\"index.php?act=pos\">Back to POS Page</a>";
					
					} else {
					
						// If we have a success we'll see this message
						if (isset($_POST['submit'])) {
						
							if (isset($_SESSION['success'])) {
								
								echo $_SESSION['success'];
								unset($_SESSION['success']);
								
							}
							
							$promo->editPosItem($_GET['id'], $_POST);
							echo $promo->displayPosEditForm($_GET['id']);
							
							// Unset the post so it doesn't get confused if we need to edit more
							unset($_POST);
						
						} else {
						
							// Display our pos edit form
							echo $promo->displayPosEditForm($_GET['id']);
							
						}
						
					}
				
				?>
			
			</div>
		</div>
	</div>
	
	<div id="leftcolumn">
		<div class="innertube">
			<?php
			
				echo $admindisplay->display_main_admin_nav();
			
			?>
		</div>
	</div>
	
	<div id="footer"><p>&copy; Caramba Marketing</p></div>

</div>

<?php
$gendisplay->body_close();
$gendisplay->html_close();
?>